package com.aliyun.edu.advanced.development.thread.thread.pool;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author xiaoming
 * @version 1.0
 * @date 2019-04-05 23:23
 **/
@Deprecated
public class Demo1  {

    public static void main(String[] args) throws Exception {


        // 创建一个无限大小线程池模型 (实际中不允许使用Executors创建线程池)
//        ExecutorService executorService = Executors.newCachedThreadPool();
        // 单线程
//        ExecutorService executorService = Executors.newSingleThreadExecutor();
        // 固定线程
        ExecutorService executorService = Executors.newFixedThreadPool(3);

        for (int x = 0; x < 10; x++) {
//            Thread.sleep(1000); // 等了一下
            int y = x;
            executorService.submit(() -> {
                System.out.println(Thread.currentThread().getName() + ", x=" + y);
            }); // 执行线程
        }
        // 关闭线程池
        executorService.shutdown();

    }

}

